package Leetcode;

import java.util.*;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class longestConsecutive {
    public int longestConsecutive(int[] nums) {
        if (nums.length == 0){
            return 0;
        }
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int result = 0;
        for (Integer i : set) {
            if (!set.contains(i - 1)){
                int curNum = i;
                int curTemp = 1;
                while (set.contains(curNum + 1)){
                    curNum++;
                    curTemp++;
                }
                result = Math.max(curTemp, result);
            }
        }
        return result;
    }
}
